﻿
using System.Net.Http.Headers;
using System.Net.Sockets;

namespace Company.Plc
{
    public abstract class PlcBase : IPlc
    {
        protected TcpClient tcpClient;
        protected PlcConfig plcConfig;
        public bool Initialized { get; private set; }

        public bool Connected { get; private set; }

        public string Message { get; private set; }

        public virtual void Close()
        {
            
        }

        public bool Init(PlcConfig config)
        {
            if (Initialized) 
                return Initialized;

            plcConfig = config;
            bool result = DoInit();
            if (result)
            {
                Initialized = true;
                Message = "初始化成功";
            }
            return result;
        }

        /// <summary>
        /// 在子类中必须实现的加载方法
        /// </summary>
        /// <returns></returns>
        public abstract bool DoInit();

        public abstract ushort[] Read(string address, ushort length);

        public abstract bool Write(string address, ushort value);

        public abstract bool Write(string address, ushort[] value);
    }
}
